﻿using AutoMapper;
using MediatR;
using S_Gridding.Api.Application.Commands.MeshType;
using S_Gridding.Domains.BasicData;
using S_Gridding.Infrastructure.Interface;
using S_Gridding.Infrastructure.Interface.IWrite;

namespace S_Gridding.Api.Application.CommandsHanders.MeshTypeHanders
{
    /// <summary>
    /// SqlSugar 中介者模式下的修改 网格类型管理表
    /// </summary>
    public class MeshTypeSqlSuageUpdateCommandHander : IRequestHandler<MeshTypeSqlSuageUpdateCommand, int>
    {
        private readonly IMeshTypeRepository _meshTypeRepository; //网格类型管理表仓储接口
        private readonly IMapper _mapper;  //automapper使用

        public MeshTypeSqlSuageUpdateCommandHander(IMeshTypeRepository meshTypeRepository, IMapper mapper)
        {
            _meshTypeRepository = meshTypeRepository;
            _mapper = mapper;
        }
        public async Task<int> Handle(MeshTypeSqlSuageUpdateCommand request, CancellationToken cancellationToken)
        {
            var res = _mapper.Map<MeshTypeInfo>(request);
            return await _meshTypeRepository.UpdateAsync(res);
        }
    }
}
